package com.ruoyi.web.controller.books;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.books.domain.BooksTools;
import com.ruoyi.books.service.IBooksToolsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 非遗制作工具Controller
 *
 * @author ruoyi
 * @date 2024-03-28
 */
@Anonymous
@RestController
@RequestMapping("/books/tools")
public class BooksToolsController extends BaseController
{
    @Autowired
    private IBooksToolsService booksToolsService;

    /**
     * 查询非遗制作工具列表
     */
//    @PreAuthorize("@ss.hasPermi('books:tools:list')")
    @GetMapping("/list")
    public TableDataInfo list(BooksTools booksTools)
    {
        startPage();
        List<BooksTools> list = booksToolsService.selectBooksToolsList(booksTools);
        return getDataTable(list);
    }

    /**
     * 导出非遗制作工具列表
     */
//    @PreAuthorize("@ss.hasPermi('books:tools:export')")
    @Log(title = "非遗制作工具", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BooksTools booksTools)
    {
        List<BooksTools> list = booksToolsService.selectBooksToolsList(booksTools);
        ExcelUtil<BooksTools> util = new ExcelUtil<BooksTools>(BooksTools.class);
        util.exportExcel(response, list, "非遗制作工具数据");
    }

    /**
     * 获取非遗制作工具详细信息
     */
//    @PreAuthorize("@ss.hasPermi('books:tools:query')")
    @GetMapping(value = "/{toolsId}")
    public AjaxResult getInfo(@PathVariable("toolsId") Long toolsId)
    {
        return success(booksToolsService.selectBooksToolsByToolsId(toolsId));
    }

    /**
     * 新增非遗制作工具
     */
//    @PreAuthorize("@ss.hasPermi('books:tools:add')")
    @Log(title = "非遗制作工具", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BooksTools booksTools)
    {
        return toAjax(booksToolsService.insertBooksTools(booksTools));
    }

    /**
     * 修改非遗制作工具
     */
//    @PreAuthorize("@ss.hasPermi('books:tools:edit')")
    @Log(title = "非遗制作工具", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BooksTools booksTools)
    {
        return toAjax(booksToolsService.updateBooksTools(booksTools));
    }

    /**
     * 删除非遗制作工具
     */
//    @PreAuthorize("@ss.hasPermi('books:tools:remove')")
    @Log(title = "非遗制作工具", businessType = BusinessType.DELETE)
	@DeleteMapping("/{toolsIds}")
    public AjaxResult remove(@PathVariable Long[] toolsIds)
    {
        return toAjax(booksToolsService.deleteBooksToolsByToolsIds(toolsIds));
    }
}
